var PW = {

    options:function () { },

    load:function () { },

    el:{ },

    events:function () { },

    ajax:function (obj,success) {
        console.log('ajaxObject', obj);
        $('#loader').addClass('show');
        //$('#loader-back').fadeIn();
        $.ajax({
            type:'post',
            dataType:'json',
            url:'/service',
            data:obj,
            success:function (response) {
                console.log('response', response);
                success(response);
                $('#loader').removeClass('show');
                /*
                setTimeout(function () {
                    $('#loader-back').fadeOut();
                },1000);
                */

            },
            error:function (jqXHR, textStatus, errorThrown ) {

                $('#loader').removeClass('show');
                /*
                setTimeout(function () {
                    $('#loader-back').fadeOut();
                },1000);
                */

                console.error('Ajax ERROR', jqXHR);
                console.error('response', jqXHR.responseText);
            }
        });
    },

    init:function () {
        this.options();
        this.load();
        this.events();

        $('[href=#loginModal]').attr('data-toggle',"modal");
        $('#menu').fadeIn();
    },

    formatTime:function(time) {

        var s = time+"";
        while (s.length < 4) s = "0" + s;
        var g = [s.slice(0, 2), ':', s.slice(2)].join('');
        return g;
    }
};

$(function () {
    "use strict";

    PW.init();
});

$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
